package com.carl.zlds.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.DigestUtils;

import java.util.Date;
import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("token")
public class Token {
    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField("token")
    private String token;

    @TableField("status")
    private Integer status;

    @TableField("user_id")
    private Long userId;

    @TableField("weight")
    private Integer weight;

    @TableField("create_time")
    private Date createTime;

    @TableField(value = "update_time", update = "now()")
    private Date updateTime;

    public static String makeToken() {
        String token = System.currentTimeMillis() + ":" + Math.random() + ":" + UUID.randomUUID().toString();
        return DigestUtils.md5DigestAsHex(token.getBytes());
    }
}